package com.skq.exception;

import com.skq.pojo.Result;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * @author skq
 * @data 2024/6/5
 * 自定义全局异常处理器，处理不满足正则的异常
 * 需要配合@Pattern注解使用
 */
@RestControllerAdvice
public class GlobalConstraintViolationExceptionHandler {

    @ExceptionHandler(Exception.class)
    public Result handleException(Exception e) {
        e.printStackTrace();
        return Result.error(StringUtils.hasLength(e.getMessage()) ? e.getMessage() : "操作失败");
    }
}
